﻿/*
* 创建者：LIYINFAI
* 创建时间：2023/10/24 9:35:26
* 描述：
* --------------------------------------
* 修改说明：
* --------------------------------------
*/
using CommonLibrary.Forms;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;

namespace CommonLibrary
{
    /// <summary>
    /// 窗体等待对象
    /// </summary>
    public class WaitingEntity
    {
        /// <summary>
        /// 窗体
        /// </summary>
        public HWFrmBase Win { get; set; }
        /// <summary>
        /// 等待信息
        /// </summary>
        public string Message { get; set; }
    }

    /// <summary>
    /// 一个出站信号多组电芯的情况
    /// </summary>
    public class MultiPLCStationTag
    {
        /// <summary>
        /// 配置文件路径
        /// </summary>
        private static string CONFIG_FILE_PATH = Path.Combine(CommonHelper.COMMON_CONFIG_DIR, "MultiPLCStationTag.json");
        /// <summary>
        /// 出站PLC地址组合
        /// </summary>
        [JsonProperty(PropertyName = "multiStationTags")]
        public List<MultiPLCTagParameter> MultiStationTagList { get; set; } = new List<MultiPLCTagParameter>();
        /// <summary>
        /// 加载配置信息
        /// </summary>
        /// <returns></returns>
        public static MultiPLCStationTag Load()
        {
            CommonHelper.CheckFile(CONFIG_FILE_PATH);
            MultiPLCStationTag pLCStationTag = new MultiPLCStationTag();
            string content = File.ReadAllText(CONFIG_FILE_PATH, CommonHelper.ENCODING);
            try
            {
                if (!string.IsNullOrWhiteSpace(content))
                    pLCStationTag.MultiStationTagList = JsonConvert.DeserializeObject<List<MultiPLCTagParameter>>(content);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            if (pLCStationTag.MultiStationTagList == null)
            {
                pLCStationTag.MultiStationTagList = new List<MultiPLCTagParameter>();
            }
            return pLCStationTag;
        }
        /// <summary>
        /// 保存配置信息
        /// </summary>
        public void Save()
        {
            string content = JsonConvert.SerializeObject(this.MultiStationTagList, Formatting.Indented);
            File.WriteAllText(CONFIG_FILE_PATH, content, CommonHelper.ENCODING);
        }
    }
    /// <summary>
    /// HIOKI3153业务相关PLC地址
    /// </summary>
    public class HIOKI3153PLCEntity
    {
        /// <summary>
        /// 触发读取结果地址
        /// </summary>
        [Description("触发读取结果地址")]
        [JsonProperty(PropertyName = "TriggerResultAddress")]
        public string TriggerResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 电压地址
        /// </summary>
        [Description("电压地址")]
        [JsonProperty(PropertyName = "VoltageAddress")]
        public string VoltageAddress { get; set; } = string.Empty;
        /// <summary>
        /// 电流地址
        /// </summary>
        [Description("电流地址")]
        [JsonProperty(PropertyName = "CurrentAddress")]
        public string CurrentAddress { get; set; } = string.Empty;
        /// <summary>
        /// 时间地址
        /// </summary>
        [Description("时间地址")]
        [JsonProperty(PropertyName = "TimesAddress")]
        public string TimesAddress { get; set; } = string.Empty;

        /// <summary>
        /// 判定结果地址
        /// </summary>
        [Description("判定结果地址")]
        [JsonProperty(PropertyName = "JudgeResultAddress")]
        public string JudgeResultAddress { get; set; } = string.Empty;

        /// <summary>
        /// 备注
        /// </summary>
        [Description("备注")]
        [JsonProperty(PropertyName = "Remark")]
        public string Remark { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }

    /// <summary>
    /// HIOKIST5520业务相关PLC地址
    /// </summary>
    public class HIOKIST5520PLCEntity
    {
        /// <summary>
        /// 触发读取结果地址
        /// </summary>
        [Description("触发读取结果地址")]
        [JsonProperty(PropertyName = "TriggerResultAddress")]
        public string TriggerResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 结果地址
        /// </summary>
        [Description("结果地址")]
        [JsonProperty(PropertyName = "ResultAddress")]
        public string ResultAddress { get; set; } = string.Empty;

        /// <summary>
        /// 判定结果地址
        /// </summary>
        [Description("判定结果地址")]
        [JsonProperty(PropertyName = "JudgeResultAddress")]
        public string JudgeResultAddress { get; set; } = string.Empty;

        /// <summary>
        /// 备注
        /// </summary>
        [Description("备注")]
        [JsonProperty(PropertyName = "Remark")]
        public string Remark { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }
    /// <summary>
    /// 扫码枪业务相关PLC地址
    /// </summary>
    public class ScanPLCEntity
    {
        /// <summary>
        /// 触发扫码地址
        /// </summary>
        [Description("触发扫码地址")]
        [JsonProperty(PropertyName = "TriggerAddress")]
        public string TriggerAddress { get; set; } = string.Empty;
        /// <summary>
        /// 条码地址
        /// </summary>
        [Description("条码地址")]
        [JsonProperty(PropertyName = "BarcodeAddress")]
        public string BarcodeAddress { get; set; } = string.Empty;
        /// <summary>
        /// 扫码结果地址
        /// </summary>
        [Description("扫码结果地址")]
        [JsonProperty(PropertyName = "ScanResultAddress")]
        public string ScanResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 扫码时间地址
        /// </summary>
        [Description("扫码时间地址")]
        [JsonProperty(PropertyName = "ScanTimeAddress")]
        public string ScanTimeAddress { get; set; } = string.Empty;
        /// <summary>
        /// 扫码完成地址
        /// </summary>
        [Description("扫码完成地址")]
        [JsonProperty(PropertyName = "ResultDoneAddress")]
        public string ResultDoneAddress { get; set; } = string.Empty;
        /// <summary>
        /// MES上传结果
        /// </summary>
        [Description("MES上传结果地址")]
        [JsonProperty(PropertyName = "ScanMESAddress")]
        public string ScanMESAddress { get; set; } = string.Empty;
        /// <summary>
        /// 备注
        /// </summary>
        [Description("备注")]
        [JsonProperty(PropertyName = "Remark")]
        public string Remark { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }

    /// <summary>
    /// RJ6902 hipot 业务相关PLC地址
    /// </summary>
    public class RJ6902PLCEntity
    {
        /// <summary>
        /// 测试完成地址
        /// </summary>
        [Description("测试完成地址")]
        [JsonProperty(PropertyName = "TestDoneAddress")]
        public string TestDoneAddress { get; set; } = string.Empty;
        /// <summary>
        /// 从机地址
        /// </summary>
        [Description("从机地址")]
        [JsonProperty(PropertyName = "MachineAddress")]
        public short MachineAddress { get; set; } = 2;
        /// <summary>
        /// Vd1
        /// </summary>
        [Description("Vd1地址")]
        [JsonProperty(PropertyName = "Vd1Address")]
        public string Vd1Address { get; set; } = string.Empty;
        /// <summary>
        /// Vd2
        /// </summary>
        [Description("Vd2地址")]
        [JsonProperty(PropertyName = "Vd2Address")]
        public string Vd2Address { get; set; } = string.Empty;
        /// <summary>
        /// Vd3
        /// </summary>
        [Description("Vd3地址")]
        [JsonProperty(PropertyName = "Vd3Address")]
        public string Vd3Address { get; set; } = string.Empty;
        /// <summary>
        /// Vp电压
        /// </summary>
        [Description("Vp电压地址")]
        [JsonProperty(PropertyName = "VpAddress")]
        public string VpAddress { get; set; } = string.Empty;
        /// <summary>
        /// Upt升压时间 (ms)
        /// </summary>
        [Description("Upt升压时间地址")]
        [JsonProperty(PropertyName = "UptAddress")]
        public string UptAddress { get; set; } = string.Empty;
        /// <summary>
        /// Rtd电阻测试数据
        /// </summary>
        [Description("Rtd电阻测试数据地址")]
        [JsonProperty(PropertyName = "RtdAddress")]
        public string RtdAddress { get; set; } = string.Empty;
        /// <summary>
        /// 电容测试数据地址
        /// </summary>
        [Description("电容测试数据地址")]
        [JsonProperty(PropertyName = "CapDataAddress")]
        public string CapDataAddress { get; set; } = string.Empty;
        /// <summary>
        /// Oc开路结果
        /// </summary>
        [Description("Oc开路结果地址")]
        [JsonProperty(PropertyName = "OcAddress")]
        public string OcAddress { get; set; } = string.Empty;
        /// <summary>
        /// Sc严重短路结果
        /// </summary>
        [Description("Sc严重短路结果地址")]
        [JsonProperty(PropertyName = "ScAddress")]
        public string ScAddress { get; set; } = string.Empty;
        /// <summary>
        /// Uv欠压结果
        /// </summary>
        [Description("Uv欠压结果地址")]
        [JsonProperty(PropertyName = "UvAddress")]
        public string UvAddress { get; set; } = string.Empty;
        /// <summary>
        /// Ov过压结果
        /// </summary>
        [Description("Ov过压结果地址")]
        [JsonProperty(PropertyName = "OvAddress")]
        public string OvAddress { get; set; } = string.Empty;
        /// <summary>
        /// Drop1跌落1结果
        /// </summary>
        [Description("Drop1跌落1结果地址")]
        [JsonProperty(PropertyName = "Drop1Address")]
        public string Drop1Address { get; set; } = string.Empty;
        /// <summary>
        /// Drop2跌落2结果
        /// </summary>
        [Description("Drop2跌落2结果地址")]
        [JsonProperty(PropertyName = "Drop2Address")]
        public string Drop2Address { get; set; } = string.Empty;
        /// <summary>
        /// Drop3跌落3结果
        /// </summary>
        [Description("Drop3跌落3结果地址")]
        [JsonProperty(PropertyName = "Drop3Address")]
        public string Drop3Address { get; set; } = string.Empty;
        /// <summary>
        /// TL结果
        /// </summary>
        [Description("TL结果地址")]
        [JsonProperty(PropertyName = "TLAddress")]
        public string TLAddress { get; set; } = string.Empty;
        /// <summary>
        /// TH结果
        /// </summary>
        [Description("TH结果地址")]
        [JsonProperty(PropertyName = "THAddress")]
        public string THAddress { get; set; } = string.Empty;
        /// <summary>
        /// 电阻测试结果
        /// </summary>
        [Description("电阻测试结果地址")]
        [JsonProperty(PropertyName = "RtrAddress")]
        public string RtrAddress { get; set; } = string.Empty;
        /// <summary>
        /// 电容测试结果地址
        /// </summary>
        [Description("电容测试结果地址")]
        [JsonProperty(PropertyName = "CapResultAddress")]
        public string CapResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// Hi-Pot总结果
        /// </summary>
        [Description("HiPot总结果地址")]
        [JsonProperty(PropertyName = "HipotResultAddress")]
        public string HipotResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }

    /// <summary>
    /// 氦检仪背景漏率业务相关PLC地址
    /// </summary>
    public class HeliumBackRatePLCEntity
    {
        /// <summary>
        /// 背景漏率检测结果地址
        /// </summary>
        [Description("背景漏率检测结果地址")]
        [JsonProperty(PropertyName = "BackgroudJudgeAddress")]
        public string BackgroudJudgeAddress { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }
    /// <summary>
    /// 氦检仪氦检业务相关PLC地址
    /// </summary>
    public class HeliumCheckPLCEntity
    {
        /// <summary>
        /// 允许读取地址（背景漏率是否正常）
        /// </summary>
        [Description("允许读取地址（背景漏率是否正常）")]
        [JsonProperty(PropertyName = "ReadPermitAddress")]
        public string ReadPermitAddress { get; set; } = string.Empty;
        /// <summary>
        /// 氦检判定结果地址
        /// </summary>
        [Description("氦检判定结果地址")]
        [JsonProperty(PropertyName = "HeliumJudgeAddress")]
        public string HeliumJudgeAddress { get; set; } = string.Empty;
        /// <summary>
        /// 漏率地址
        /// </summary>
        [Description("漏率地址")]
        [JsonProperty(PropertyName = "LeakValueAddress")]
        public string LeakValueAddress { get; set; } = string.Empty;
        /// <summary>
        /// 压力地址
        /// </summary>
        [Description("压力地址")]
        [JsonProperty(PropertyName = "PressValueAddress")]
        public string PressValueAddress { get; set; } = string.Empty;
        /// <summary>
        /// 氦检时间地址
        /// </summary>
        [Description("氦检时间地址")]
        [JsonProperty(PropertyName = "HeliumTimesAddress")]
        public string HeliumTimesAddress { get; set; } = string.Empty;
        /// <summary>
        /// 氦检结果地址
        /// </summary>
        [Description("氦检结果地址")]
        [JsonProperty(PropertyName = "HeliumResultAddress")]
        public string HeliumResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }

    /// <summary>
    /// Modbus地址定义
    /// </summary>
    public class ModbusPositionEntity
    {
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{this.Category}-{this.Name}-{this.Address.ToString("X4")}-{this.DataType}-{this.TargetDataType}";
        }
        /// <summary>
        /// 名目
        /// </summary>
        [JsonProperty(PropertyName = "Category")]
        public string Category { get; set; } = string.Empty;
        /// <summary>
        /// 名称
        /// </summary>
        [JsonProperty(PropertyName = "Name")]
        public string Name { get; set; } = string.Empty;
        /// <summary>
        /// 默认值
        /// </summary>
        [JsonProperty(PropertyName = "DefaultValue")]
        public string DefaultValue { get; set; } = string.Empty;

        /// <summary>
        /// 地址
        /// </summary>
        [JsonProperty(PropertyName = "Address")]
        public int Address { get; set; }
        /// <summary>
        /// 个数
        /// </summary>
        [JsonProperty(PropertyName = "Length")]
        public ushort Length { get; set; } = 1;
        /// <summary>
        /// 类型
        /// </summary>
        [JsonProperty(PropertyName = "DataType")]
        public EDataType DataType { get; set; } = EDataType.SHORT;
        /// <summary>
        /// 目标类型
        /// </summary>
        [JsonProperty(PropertyName = "TargetDataType")]
        public EDataType TargetDataType { get; set; } = EDataType.SHORT;
        /// <summary>
        /// 转换中间值
        /// </summary>
        [JsonProperty(PropertyName = "MidConvertValue")]
        public object MidConvertValue { get; set; }
        /// <summary>
        /// 是否需要转换
        /// </summary>
        [JsonProperty(PropertyName = "IsNumberConvert")]
        public bool IsNumberConvert { get; set; } = false;
        /// <summary>
        /// PLC地址
        /// </summary>
        [JsonProperty(PropertyName = "PLCAddress")]
        public string PLCAddress { get; set; } = string.Empty;
        /// <summary>
        /// 数据转换
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public object Convert(object value)
        {
            object result = value;
            try
            {
                if (this.IsNumberConvert
                    && this.DataType.Equals(this.TargetDataType)
                    && this.MidConvertValue != null)
                {
                    switch (this.TargetDataType)
                    {
                        case EDataType.SHORT:
                            result = (short)((short)value * (short.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.INT:
                            result = (int)((int)value * (int.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.UINT:
                            result = (uint)((uint)value * (uint.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.USHORT:
                            result = (ushort)((ushort)value * (ushort.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.FLOAT:
                            result = (float)((float)value * (float.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.DOUBLE:
                            result = (double)((double)value * (double.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.LONG:
                            result = (long)((long)value * (long.Parse(this.MidConvertValue.ToString())));
                            break;
                        case EDataType.ULONG:
                            result = (ulong)((ulong)value * (ulong.Parse(this.MidConvertValue.ToString())));
                            break;
                    }
                }
                else
                if (this.IsNumberConvert
                    && !this.DataType.Equals(this.TargetDataType)
                    && this.MidConvertValue != null)
                {
                    if (this.TargetDataType.Equals(EDataType.FLOAT))
                    {
                        switch (this.DataType)
                        {
                            case EDataType.SHORT:
                                result = float.Parse((float.Parse(this.MidConvertValue.ToString()) * (short)value).ToString("F2"));
                                break;
                            case EDataType.USHORT:
                                result = float.Parse((float.Parse(this.MidConvertValue.ToString()) * (ushort)value).ToString("F2"));
                                break;
                            case EDataType.INT:
                                result = float.Parse((float.Parse(this.MidConvertValue.ToString()) * (int)value).ToString("F2"));
                                break;
                            case EDataType.UINT:
                                result = float.Parse((float.Parse(this.MidConvertValue.ToString()) * (int)value).ToString("F2"));
                                break;
                            case EDataType.LONG:
                                result = float.Parse((float.Parse(this.MidConvertValue.ToString()) * (long)value).ToString("F2"));
                                break;
                            case EDataType.ULONG:
                                result = float.Parse((float.Parse(this.MidConvertValue.ToString()) * (long)value).ToString("F2"));
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return result;
        }
        /// <summary>
        /// 备注
        /// </summary>
        [JsonProperty(PropertyName = "Remark")]
        public string Remark { get; set; } = string.Empty;
    }

    /// <summary>
    /// Gagf称重天平业务相关PLC地址
    /// </summary>
    public class GagfRezeroPLCEntity
    {
        /// <summary>
        /// 清零完成地址
        /// </summary>
        [Description("清零完成地址")]
        [JsonProperty(PropertyName = "ZeroDoneAddress")]
        public string ZeroDoneAddress { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }

    /// <summary>
    /// Gagf称重天平业务相关PLC地址
    /// </summary>
    public class GagfWeightPLCEntity
    {
        /// <summary>
        /// 称重结果地址
        /// </summary>
        [Description("称重结果地址")]
        [JsonProperty(PropertyName = "ResultAddress")]
        public string ResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 称重完成地址
        /// </summary>
        [Description("称重完成地址")]
        [JsonProperty(PropertyName = "ResultDoneAddress")]
        public string ResultDoneAddress { get; set; } = string.Empty;
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return CommonHelper.GetObjectString(this);
        }
    }
    /// <summary>
    /// modbus信息
    /// </summary>
    public class ModbusEntity
    {
        /// <summary>
        /// 名称
        /// </summary>
        [JsonProperty(PropertyName = "Name")]
        public string Name { get; set; } = string.Empty;
        /// <summary>
        /// TCP信息
        /// </summary>
        [JsonProperty(PropertyName = "TcpEntity")]
        public TcpEntity TcpEntity { get; set; }
        /// <summary>
        /// 串口信息
        /// </summary>
        [JsonProperty(PropertyName = "SerialEntity")]
        public SerialEntity SerialEntity { get; set; }
        /// <summary>
        /// 通讯方式
        /// </summary>
        [JsonProperty(PropertyName = "CommunicationType")]
        public ECommunicationType CommunicationType { get; set; } = ECommunicationType.MODBUS_TCP;
        /// <summary>
        /// 站点
        /// </summary>
        [JsonProperty(PropertyName = "Station")]
        public byte Station { get; set; }
        /// <summary>
        /// 是否字符串反转
        /// </summary>
        [JsonProperty(PropertyName = "IsStringReserve")]
        public bool IsStringReserve { get; set; } = false;
        /// <summary>
        /// 数据顺序
        /// </summary>
        [JsonProperty(PropertyName = "Format")]
        public EDataFormat Format { get; set; } = EDataFormat.CDAB;
        /// <summary>
        /// 读取地址
        /// </summary>
        [JsonProperty(PropertyName = "AddressList")]
        public List<ModbusPositionEntity> AddressList { get; set; } = new List<ModbusPositionEntity>();
        /// <summary>
        /// 读取的数据
        /// </summary>
        [JsonIgnore]
        public Dictionary<string, object> Datas { get; set; } = new Dictionary<string, object>();
    }

    /// <summary>
    /// 串口信息
    /// </summary>
    public class SerialEntity
    {
        /// <summary>
        /// 端口名称
        /// </summary>
        public string PortName { get; set; } = string.Empty;
        /// <summary>
        /// 波特率
        /// </summary>
        public int BaudRate { get; set; } = 9600;
        /// <summary>
        /// 校验位
        /// </summary>
        public int ParityBit { get; set; } = 0;
        /// <summary>
        /// 数据位
        /// </summary>
        public int DataBit { get; set; } = 8;
        /// <summary>
        /// 停止位
        /// </summary>
        public int StopBit { get; set; } = 1;
    }
    /// <summary>
    /// tcp信息
    /// </summary>
    public class TcpEntity
    {
        /// <summary>
        /// IP
        /// </summary>
        public string IP { get; set; }
        /// <summary>
        /// 端口
        /// </summary>
        public int Port { get; set; }
        /// <summary>
        /// 描述信息
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"IP: {IP}，Port：{Port}";
        }
    }
    /// <summary>
    /// 行为触发器
    /// </summary>
    public class TriggerHandler
    {
        /// <summary>
        /// 处理方法名称
        /// </summary>
        public string HandlerName { get; set; } = string.Empty;
        /// <summary>
        /// 触发地址
        /// </summary>
        public string TriggerAddress { get; set; } = string.Empty;
        /// <summary>
        /// 触发的值类型
        /// </summary>
        public EDataType TriggerDataType { get; set; } = EDataType.SHORT;
        /// <summary>
        /// 触发的值
        /// </summary>
        public object TriggerValue { get; set; } = (short)1;
        /// <summary>
        /// 重置的值
        /// </summary>
        public object ResetValue { get; set; } = (short)0;
        /// <summary>
        /// 其他PLC地址信息
        /// </summary>
        public object OtherAddress { get; set; } = null;
        /// <summary>
        /// 其他数据信息
        /// </summary>
        public object OtherData { get; set; } = null;
        /// <summary>
        /// 触发的行为
        /// </summary>
        public EHandlerType HandlerType { get; set; }
    }
    /// <summary>
    /// 出站完成交互信息
    /// </summary>
    public class OutboundFinishExcuteEntity
    {
        /// <summary>
        /// 出站完成的地址
        /// </summary>
        public string DoneAddress { get; set; } = string.Empty;
        /// <summary>
        /// 出站触发的地址
        /// </summary>
        public string TriggerAddress { get; set; } = string.Empty;
    }


    /// <summary>
    /// 产品计数信息
    /// </summary>
    public class ProductCountExcuteEntity
    {
        /// <summary>
        /// 来料数量地址
        /// </summary>
        public int InboundNum { get; set; } = 0;
        /// <summary>
        /// 出料数量地址
        /// </summary>
        public int OutboundNum { get; set; } = 0;
        /// <summary>
        /// 扫码NG数量地址
        /// </summary>
        public int ScanNGNum { get; set; } = 0;
        /// <summary>
        /// 氦检数量地址
        /// </summary>
        public int HeliumNum { get; set; } = 0;
        /// <summary>
        /// 氦检NG数量地址
        /// </summary>
        public int HeliumNGNum { get; set; } = 0;
        /// <summary>
        /// 耐压测试数量地址
        /// </summary>
        public int PressTestNum { get; set; } = 0;
        /// <summary>
        /// 耐压测试NG数量地址
        /// </summary>
        public int PressTestNGNum { get; set; } = 0;
        /// <summary>
        /// 绝缘测试数量地址
        /// </summary>
        public int InsulationTestNum { get; set; } = 0;
        /// <summary>
        /// 绝缘测试NG数量地址
        /// </summary>
        public int InsulationTestNGNum { get; set; } = 0;
    }
    /// <summary>   
    /// 出站交互信息
    /// </summary>
    public class OutboundExcuteEntity
    {
        /// <summary>
        /// 出站结果的地址
        /// </summary>
        public string ResultAddress { get; set; } = string.Empty;
        /// <summary>
        /// 出站 PLC 交互地址
        /// </summary>
        public List<PLCTagSetting> PLCTags = new List<PLCTagSetting>();
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; } = string.Empty;
        /// <summary>
        /// 出站类型
        /// </summary>
        public EOutType OutType { get; set; } = EOutType.FINAL;
        /// <summary>
        /// 电池下标
        /// </summary>
        public int Index { get; set; } = 0;
    }

    /// <summary>
    /// Hipot 交互信息
    /// </summary>
    public class RJ6902ExcuteEntity
    {
        /// <summary>
        /// 仪器返回值
        /// </summary>
        public byte[] Data { get; set; } = null;
        /// <summary>
        /// 参数查询 PLC 交互地址
        /// </summary>
        public RJ6902GXQueryParameterSetting QueryPLCEntity { get; set; } = null;
        /// <summary>
        /// 启动测试 PLC 交互地址
        /// </summary>
        public RJ6902PLCEntity PLCEntity { get; set; } = null;
        /// <summary>
        /// 是否正常
        /// </summary>
        public bool IsOK { get; set; } = false;
        /// <summary>
        /// 结果
        /// </summary>
        public string Result { get; set; } = string.Empty;
    }
    /// <summary>
    /// MES 设备状态 交互信息
    /// </summary>
    public class MESStatusExcuteEntity
    {
        /// <summary>
        /// 报警代码
        /// </summary>
        public EPLCState Status { get; set; } = EPLCState.Idle;
    }
    /// <summary>
    /// MES Alarm 交互信息
    /// </summary>
    public class MESAlarmExcuteEntity
    {
        /// <summary>
        /// 报警代码
        /// </summary>
        public string AlarmCode { get; set; } = string.Empty;
        /// <summary>
        /// 报警内容
        /// </summary>
        public string AlarmContent { get; set; } = string.Empty;
        /// <summary>
        /// 开始时间
        /// </summary>
        public string StartTime { get; set; } = string.Empty;
        /// <summary>
        /// 结束时间
        /// </summary>
        public string EndTime { get; set; } = string.Empty;
    }
    /// <summary>
    /// 扫码交互信息
    /// </summary>
    public class ScanExcuteEntity
    {
        /// <summary>
        /// 条码
        /// </summary>
        public string Barcode { get; set; } = string.Empty;
        /// <summary>
        /// 扫码时间
        /// </summary>
        public string ScanTime { get; set; } = string.Empty;
        /// <summary>
        /// MES 结果
        /// </summary>
        public short MESResult { get; set; }
        /// <summary>
        /// 扫码结果
        /// </summary>
        public short ScanResult { get; set; }
        /// <summary>
        /// PLC 交互地址
        /// </summary>
        public ScanPLCEntity PlcEntity { get; set; }
    }

    /// <summary>
    /// HIOKI 3153交互信息
    /// </summary>
    public class HIOKI3153ExcuteEntity
    {
        /// <summary>
        /// 电压（kV）
        /// </summary>
        public float Voltage { get; set; }
        /// <summary>
        /// 电流（mA）
        /// </summary>
        public float Current { get; set; }
        /// <summary>
        /// 时间（s）
        /// </summary>
        public float Times { get; set; }
        /// <summary>
        /// 时间类型
        /// </summary>
        public short TimeType { get; set; }
        /// <summary>
        /// 判定结果
        /// </summary>
        public string JudgeResult { get; set; } = string.Empty;
        /// <summary>
        /// 判定结果值
        /// </summary>
        public short JudgeValueResult { get; set; } = 0;
        /// <summary>
        /// PLC 交互地址
        /// </summary>
        public HIOKI3153PLCEntity PlcEntity { get; set; }
    }

    /// <summary>
    /// HIOKI 状态交互信息
    /// </summary>
    public class HIOKIStatusExcuteEntity
    {
        /// <summary>
        /// 状态地址
        /// </summary>
        public string StatusAddress { get; set; }
        /// <summary>
        /// 是否已准备好
        /// </summary>
        public bool IsOK { get; set; } = false;
    }
    /// <summary>
    /// HIOKI ST5520交互信息
    /// </summary>
    public class HIOKIST5520ExcuteEntity
    {
        /// <summary>
        /// 测量值
        /// </summary>
        public float MeasureResult { get; set; }
        /// <summary>
        /// 判定结果
        /// </summary>
        public string JudgeResult { get; set; } = string.Empty;
        /// <summary>
        /// 判定结果值
        /// </summary>
        public short JudgeValueResult { get; set; }
        /// <summary>
        /// PLC 交互地址
        /// </summary>
        public HIOKIST5520PLCEntity PlcEntity { get; set; }
    }

    /// <summary>
    /// 氦检交互信息
    /// </summary>
    public class HeliumExcuteEntity
    {
        /// <summary>
        /// 漏率
        /// </summary>
        public float LeakRate { get; set; } = 0f;
        /// <summary>
        /// 检漏口压力
        /// </summary>
        public float LeakPress { get; set; } = 0f;
        /// <summary>
        /// 状态
        /// </summary>
        public short Status { get; set; } = 0;
        /// <summary>
        /// 是否正常
        /// </summary>
        public bool IsNormal { get; set; } = false;
        /// <summary>
        /// PLC 交互地址
        /// </summary>
        public string OtherAddress { get; set; } = string.Empty;
        /// <summary>
        /// 允许读取地址
        /// </summary>
        public List<string> ReadPermitAddresses { get; set; } = new List<string>();

        /// <summary>
        /// 是否允许读取
        /// </summary>
        public short AllowReadPermit { get; set; } = 0;

        /// <summary>
        /// 结果
        /// </summary>
        public short Result { get; set; } = 0;
    }
    /// <summary>
    /// 天平交互信息
    /// </summary>
    public class GAGFExcuteEntity
    {
        /// <summary>
        /// 重量
        /// </summary>
        public string Weight { get; set; } = string.Empty;
        /// <summary>
        /// 重量相关 PLC 交互地址
        /// </summary>
        public GagfWeightPLCEntity WeightPLCEntity { get; set; }
        /// <summary>
        /// 清零相关 PLC 交互地址
        /// </summary>
        public GagfRezeroPLCEntity RezeroPLCEntity { get; set; }
    }
    /// <summary>
    /// PLC实体
    /// </summary>
    public class PLCEntity
    {
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; } = "PLC";
        /// <summary>
        /// 设备厂商
        /// </summary>
        public EPLCDeviceType DeviceType { get; set; } = EPLCDeviceType.OMRON;
        /// <summary>
        /// 操作类型(默认为FINS)
        /// </summary>
        public EPLCOptType OptType { get; set; } = EPLCOptType.FINS;
        /// <summary>
        /// IP
        /// </summary>
        public string IP { get; set; } = "192.168.1.16";
        /// <summary>
        /// 端口
        /// </summary>
        public int Port { get; set; } = 9600;
        /// <summary>
        /// 数值顺序(默认为CDAB)，三菱无需设置
        /// </summary>
        public EDataFormat DataFormat { get; set; } = EDataFormat.CDAB;
        /// <summary>
        /// 是否字符串反转，默认设置为 false
        /// </summary>
        public bool IsStringReserve { get; set; } = false;
        /// <summary>
        /// 站点(默认为1)，汇川的需要设置为 1，三菱，欧姆龙无需设置
        /// </summary>
        public int StationNo { get; set; } = 1;
        /// <summary>
        /// 单元号(默认为0)，欧姆龙设置为0，三菱，欧姆龙无需设置
        /// </summary>
        public int UnitNo { get; set; } = 0;
        /// <summary>
        /// 连接超时 2000ms
        /// </summary>
        public int ConnectTimeOut { get; set; } = 2000;
        /// <summary>
        /// 是否使用一个连接对象
        /// </summary>
        public bool IsSingle { get; set; } = true;

        /// <summary>
        /// 批量读取时是否分批读取
        /// </summary>
        public bool IsSplitBatchRead { get; set; } = true;
        /// <summary>
        /// 字符串编码（默认 utf-8（其他比如 ascii，utf-8 等等）
        /// </summary>
        public string StringEncoding { get; set; } = "utf-8";
    }
}
